#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include "prn_drv.h"
#include <sys/err.h>
#include "apitrans.h"

extern sys_apitrans_t sysapi;

int prn_init(void)
{
    int (*pprn_init)(void);
    
    pprn_init = sysapi(PRN_INIT_API);
    if (pprn_init) {
        return pprn_init();
    }
    return -API_UNSUPPORTED_ERR;

}
int prn_start(void)
{
    int (*pprn_start)(void);
    
    pprn_start = sysapi(PRN_START_API);
    if (pprn_start) {
        return pprn_start();
    }
    return -API_UNSUPPORTED_ERR;
}

int prn_string(const char *fmt, ...)
{
        int ret;
        
        void (*pprn_putch)(char ch, char **pca);
        
        pprn_putch = sysapi(PRN_PUTCH_API);
        if (!pprn_putch) {
            return -API_UNSUPPORTED_ERR;
        }
        va_list args;
        va_start(args,fmt);
        ret = _doprntx(fmt, args, pprn_putch, 0);
        va_end(args);

        
        return ret;
}


int prn_set_font(hz_font_em hz_font, zm_font_em zm_font)
{
    int (*pprn_set_font)(hz_font_em hz_font, zm_font_em zm_font);
    
    pprn_set_font = sysapi(PRN_SET_FONT_API);
    if (pprn_set_font) {
        return pprn_set_font(hz_font, zm_font);
    }
    return -API_UNSUPPORTED_ERR;
}
int prn_set_underline(uint8_t pstatus)
{
    int (*pprn_set_underline)(uint8_t pstatus);
    
    pprn_set_underline = sysapi(PRN_SET_UNDERLINE_API);
    if (pprn_set_underline) {
        return pprn_set_underline(pstatus);
    }
    return -API_UNSUPPORTED_ERR;
}
int prn_set_spacing(int border, int column, int row)
{
    int (*pprn_set_spacing)(int border, int column, int row);
    
    pprn_set_spacing = sysapi(PRN_SET_SPACING_API);
    if (pprn_set_spacing) {
        return pprn_set_spacing(border, column, row);
    }
    return -API_UNSUPPORTED_ERR;
}
int prn_set_grey(uint8_t grey)
{
    int (*pprn_set_grey)(uint8_t grey);
    
    pprn_set_grey = sysapi(PRN_SET_GREY_API);
    if (pprn_set_grey) {
        return pprn_set_grey(grey);
    }
    return -API_UNSUPPORTED_ERR;
}

int prn_get_status( prn_status_em *status)
{
    int (*pprn_get_status)( prn_status_em *status);
    
    pprn_get_status = sysapi(PRN_GET_STATUS_API);
    if (pprn_get_status) {
        return pprn_get_status(status);
    }
    return -API_UNSUPPORTED_ERR;
}
int prn_image(int x_size, int y_size, int x_pos, const char *img)
{
    int (*pprn_image)(int x_size, int y_size, int x_pos, const char *img);
    pprn_image = sysapi(PRN_IMAGE_API);
    if (pprn_image) {
        return pprn_image(x_size, y_size, x_pos, img);
    }
    return -API_UNSUPPORTED_ERR;
    
}

#if 0
int  prn_init(void)
{
	    return sysapi->prn_init();
}
#endif
